<template>
	<view class="index-container index-page-container">
		<!-- 轮播图 -->
		<uni-swiper-dot class="uni-swiper-dot-box" :info="data" :current="current" field="content">
			<swiper class="swiper-box" :current="swiperDotIndex" @change="changeSwiper">
				<swiper-item v-for="(item, index) in data" :key="index">
					<view class="swiper-item" @click="clickBannerItem(item)">
						<image style="height: 100%;" :src="item.image" mode="aspectFill" :draggable="false" />
					</view>
				</swiper-item>
			</swiper>
		</uni-swiper-dot>

		<!-- 宫格组件 -->
		<view class="grid-body">
			<!-- 今日 -->
			<uni-grid class="grid-content bg-blue" :column="3" :showBorder="false">
				<uni-grid-item class="grid-item">
					<view class="grid-item-box">
						<view class="num">￥ {{ form.todaySalePrice }}</view>
						<view class="text">今日销售</view>
					</view>
				</uni-grid-item>
				<uni-grid-item class="grid-item">
					<view class="grid-item-box" @click="getData">
						<uni-icons class="icon" type="refreshempty" size="30"></uni-icons>
						<view class="text">刷新</view>
					</view>
				</uni-grid-item>
				<uni-grid-item class="grid-item">
					<view class="grid-item-box">
						<view class="num">￥ {{ form.todayPurchasePrice }}</view>
						<view class="text">今日采购</view>
					</view>
				</uni-grid-item>
				<uni-grid-item class="grid-item">
					<view class="grid-item-box">
						<view class="num">￥ {{ form.receivable }}</view>
						<view class="text">应收账款</view>
					</view>
				</uni-grid-item>
				<uni-grid-item class="grid-item">
					<view class="grid-item-box">
						<view class="num">￥ {{ form.todayIncome }}</view>
						<view class="text">今日收入</view>
					</view>
				</uni-grid-item>
				<uni-grid-item class="grid-item">
					<view class="grid-item-box">
						<view class="num">￥ {{ form.payable }}</view>
						<view class="text">应付账款</view>
					</view>
				</uni-grid-item>
			</uni-grid>

			<!-- 昨日 -->
			<uni-grid class="grid-content" :column="3" :showBorder="false">
				<uni-grid-item class="grid-item">
					<view class="grid-item-box">
						<view class="text">昨日销售</view>
						<view class="num">￥ {{ form.yesterdaySalePrice }}</view>
					</view>
				</uni-grid-item>
				<uni-grid-item class="grid-item">
					<view class="grid-item-box">
						<view class="text">今日支出</view>
						<view class="num">￥ {{ form.todayPay }}</view>
					</view>
				</uni-grid-item>
				<uni-grid-item class="grid-item">
					<view class="grid-item-box">
						<view class="text">昨日采购</view>
						<view class="num">￥ {{ form.yesterdayPurchasePrice }}</view>
					</view>
				</uni-grid-item>
				<uni-grid-item class="grid-item">
					<view class="grid-item-box">
						<view class="text">本月累计销售</view>
						<view class="num">￥ {{ form.monthSalePrice }}</view>
					</view>
				</uni-grid-item>
				<uni-grid-item class="grid-item">
					<view class="grid-item-box">
						<view class="text">本月收入</view>
						<view class="num">￥ {{ form.monthIncome }}</view>
					</view>
				</uni-grid-item>
				<uni-grid-item class="grid-item">
					<view class="grid-item-box">
						<view class="text">本月累计采购</view>
						<view class="num">￥ {{ form.monthPurchasePrice }}</view>
					</view>
				</uni-grid-item>
				<uni-grid-item class="grid-item">
					<view class="grid-item-box">
						<view class="text">今年累计销售</view>
						<view class="num">￥ {{ form.yearSalePrice }}</view>
					</view>
				</uni-grid-item>
				<uni-grid-item class="grid-item">
					<view class="grid-item-box">
						<view class="text">本月支出</view>
						<view class="num">￥ {{ form.monthPay }}</view>
					</view>
				</uni-grid-item>
				<uni-grid-item class="grid-item">
					<view class="grid-item-box">
						<view class="text">今年累计采购</view>
						<view class="num">￥ {{ form.yearPurchasePrice }}</view>
					</view>
				</uni-grid-item>
			</uni-grid>
		</view>
	</view>
</template>

<script>
	import { getAppStatistics } from "@/api/index"
	
	export default {
		data() {
			return {
				current: 0,
				swiperDotIndex: 0,
				form: {},
				data: [{
						image: '/static/images/banner/banner01.png'
					},
					// {
					// 	image: '/static/images/banner/banner02.png'
					// },
					// {
					// 	image: '/static/images/banner/banner03.png'
					// },
					// {
					// 	image: '/static/images/banner/banner04.png'
					// }
				],
			}
		},
		created() {
			this.getData();
		},
		methods: {
			// 获取数据
			getData() {
				getAppStatistics().then((res)=> {
					this.form = res && res.data?res.data:{};
				})
			},
			clickBannerItem(item) {
				console.info(item)
			},
			changeSwiper(e) {
				this.current = e.detail.current
			},
			changeGrid(e) {
				this.$modal.showToast('模块建设中~')
			}
		}
	}
</script>

<style scoped lang="scss">
	/* #ifndef APP-NVUE */
	page {
		display: flex;
		flex-direction: column;
		box-sizing: border-box;
		background-color: #fff;
		min-height: 100%;
		height: auto;
	}

	view {
		font-size: 14px;
		line-height: inherit;
	}

	/* #endif */

	.text {
		text-align: center;
		font-size: 26rpx;
		margin-top: 10rpx;
	}


	.grid-content {
		position: relative;
		left: 1px;

		.grid-item {
			background: #ffffff;
			.uni-grid-item {
				height: 77px!important;
			}
		}

		&.bg-blue {
			.grid-item {
				background: #51acff;
			}

			.grid-item-box {
				border: 0.5px solid #eeeeee;
			}

			.icon {
				color: #ffffff !important;
			}

			.num {
				color: #ffffff;
			}

			.text {
				color: #ffffff;
			}
		}
	}

	.grid-item {
		.uni-grid-item {
			
		}
	}

	.grid-item-box {
		flex: 1;
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: column;
		align-items: center;
		justify-content: center;
		padding: 15px 0 15px;
		border: 0.5px solid #eeeeee;

		.icon {
			color: #333333 !important;
			margin-top: -2px;
		}

		.num {
			font-size: 18px;
			color: #333333;
		}

		.text {
			font-size: 11px;
			color: #999999;
			margin-top: 2px;
		}
	}

	.uni-margin-wrap {
		width: 690rpx;
		width: 100%;
		;
	}

	.swiper {
		height: 300rpx;
	}

	.swiper-box {
		height: 400rpx;
	}

	.swiper-item {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: column;
		justify-content: center;
		align-items: center;
		color: #fff;
		height: 100%;
	}

	@media screen and (min-width: 500px) {
		.uni-swiper-dot-box {
			width: 400px;
			/* #ifndef APP-NVUE */
			margin: 0 auto;
			/* #endif */
			margin-top: 8px;
		}

		.image {
			width: 100%;
		}
	}
	.uni-grid-item {
		height: 77px!important;
	}
</style>
<style>
	.index-page-container .grid-body {
		margin-left: 1px;
	}
	.index-page-container .grid-body .uni-grid-item {
		height: 77px!important;
	}
	.index-page-container .grid-body .uni-grid-item .uni-icons{
		color: #ffffff!important;
	}
</style>